package com.parking.platform.controller;


import com.parking.common.core.model.Result;
import com.parking.common.core.util.JwtUtil;
import com.parking.common.web.aop.Permission;
import com.parking.common.web.util.RedisUtil;
import com.parking.platform.dao.PlatformRoleResourceMapper;
import com.parking.platform.form.UpRoleResourceForm;
import com.parking.platform.service.PlatformRoleResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 香菜狗带
 * @since 2023年11月28日
 */
@RestController
@RequestMapping("/platformRoleResource")
@Api(tags = "管理员权限接口")
public class PlatformRoleResourceController {
    @Resource
    private PlatformRoleResourceService platformRoleResourceService;
    @Resource
    private RedisUtil redisUtil;

    /**
     * 修改管理员权限
     * 修改参数：
     * platformRoleResourceId:平台角色资源id
     * platformRoleId:平台角色id
     * platformResourceId:平台资源id
     *
     * */
    @PostMapping ("/modifyRoleResourceData.platform")
    @Permission(resources = {"/modifyRoleResourceData.platform"})
    @ApiOperation("/修改管理员权限")
    public Result  modifyRoleResourceData(@RequestBody List<UpRoleResourceForm> form, @RequestHeader("authorization")String authorization) throws Exception {
        String refreshToken = redisUtil.get(authorization);
        Integer adminId = JwtUtil.getPlatformId(refreshToken);
        platformRoleResourceService.modifyRoleResourceData(form,adminId);
        return Result.getResult().setCode(200).setMessage("修改管理员权限成功");
    }



}

